package com.qwert.shortlink.project.config;

import org.redisson.api.RBloomFilter;
import org.redisson.api.RedissonClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author qwert
 * @version 1.0.0
 * @create 2024/6/25 19:26
 **/
@Configuration
public class RBloomFilterConfiguration {

    /**
     * 短链接生成的布隆过滤器，
     * 存储为6位短链接数据，原始链接位用户上下文名称加链接名称
     */
    @Bean
    public RBloomFilter<String> shortLinkCreateCachePenetrationBloomFilter(RedissonClient redissonClient) {
        RBloomFilter<String> cachePenetrationBloomFilter = redissonClient.getBloomFilter("shortLinkCreateCachePenetrationBloomFilter");
        //初始化布隆过滤器：参数1：预估布隆过滤器存储的元素长度；参数2：运行的误判率
        cachePenetrationBloomFilter.tryInit(100000000, 0.001);
        return cachePenetrationBloomFilter;
    }
}
